import { Elysia, t } from "elysia";
import { db } from "./db";
import { staticPlugin } from '@elysiajs/static'
import "./autoimports"
// import { embeddedFiles } from "bun";
// console.log(embeddedFiles);
const app = new Elysia()
  .get("/api", async () => {
    await db.users.add({
      username: "John Doe",
      age: 30,
      activities: ["swimming", "cycling"],
      address: {
        country: "USA",
        city: "New York",
        street: "Main Street",
        houseNumber: 123
      }
    })
    const user = await db.users.findByPrimaryIndex("username", "John Doe")
    console.log(user?.value)
    // return user?.value
    return "hello"
  })


if (Bun.env.DEV) {
  app.use(staticPlugin({
    assets: "./ui/dist",
    prefix: "/",
  }))
} else {
  app.get("/", () => Bun.file("/$bunfs/root/index.html"))
    .get("/assets/:file", ({ params: { file } }) => Bun.file(`/$bunfs/root/${file}`))
    .get("/:file", ({ params: { file } }) => Bun.file(`/$bunfs/root/${file}`))
}

app.listen(3000);

console.log(
  `🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
);
